<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    class Employee_model extends MY_Model
    {
        public function __construct() 
        {
            parent::__construct();
            $this->tbl_name = 'employees';
        }
        
        public function getPositionForCompany($company_id)    
        {
            $sql = "SELECT p.position, p.id
                    FROM `positions` AS p
                    INNER JOIN employees ON employees.position = p.id
                    WHERE p.active = 1
                    AND employees.active = 1
                    AND employees.companies_id = $company_id";
            
            $query = $this->db->query($sql);

            $data = array();
            if ($query->num_rows() > 0)
            {
               foreach ($query->result_array() as $row)
               {
                    $data[] = $row;    
               }
               return $data;
            }   
        } 
        
        public function getEmployByPos($position_id, $company_id)               
        {
            $sql = "SELECT *
                    FROM  employees
                    WHERE active = 1 AND companies_id = $company_id AND position = '$position_id'";
            
            $query = $this->db->query($sql);

            $data = array();
            if ($query->num_rows() > 0)
            {
               foreach ($query->result_array() as $row)
               {
                    $data[] = $row;    
               }
               return $data;
            }       
        }
    }
?>
